<template>
  <table class="table table-bordered">

    <tr>
      <td align="right">借款款项名称</td>
      <td>
      <input type="text" v-model="data.Mname">
      </td>
    </tr>
    <tr>
      <td align="right">借款最高金额</td>
      <td>
      <input type="text" v-model="data.Getmon">
      </td>
    </tr>
    <tr>
      <td align="right">借款最高年限</td>
      <td>
      <input type="text" v-model="data.Getyear">
      </td>
    </tr>
    <tr>
      <td align="right">利息编号</td>
      <td>
        <select v-model="data.Lid">

          <option value="-1">请选择</option>
          <option v-for="item in hk" :value=" item.Lid ">{{ item.SNname }}</option>
        </select>
      </td>
    </tr>
    <tr>
      <td align="right">借款款项简介</td>
      <td>
      <input type="text" v-model="data.lMess">
      </td>
    </tr>
    <tr>
      <td align="right"></td>
      <td>
      <input type="button" value="提交" @click="Monadd()" class="btn btn-success">
      </td>
    </tr>
  </table>
</template>

<script setup lang="ts">



  import { reactive,toRefs,onMounted } from 'vue';

  import axios from 'axios';


  import { useRouter } from 'vue-router';


    const router=useRouter()
  let state=reactive({

    hk:[],
    data:{
      Mname:'',
      Getmon:'',
      Getyear:'',
      Lid:'-1',
      lMess:'',
    },

  })


 const {hk,data} = toRefs(state)




  //就绪函数
  onMounted(()=>{

    Monselect()

  })


//利息下拉框
  const Monselect:any=(()=>{

    axios({

      url:"https://localhost:44305/api/Default/GEtselect",
      method:"get",

    })
    .then(res=>{
      console.log(res)
      hk.value=res.data.data


    })
      .catch(err=>{



      })




  })


//添加
    const Monadd=(()=>{

      if(Number(state.data.Getmon)*0!=0)
      {
        alert('最高金额位数字');
        return;
      }
      if(Number(state.data.Getmon)<0)
      {
        alert('最高大于数字');
        return;
      }

     if(state.data.Getmon=="")
     {
      alert('最高金额不能为空');
      return;
     }   
     if(state.data.Mname=="")
     {
      alert('借款名称能为空');
      return;
     }  
     if(state.data.Getyear=="")
     {
      alert('借款年限为空');
      return;
     } 
     if(state.data.lMess=="")
     {
      alert('借款简介不能为空');
      return;
     } 



      axios({

        url:'https://localhost:44305/api/Default/ShowAdd',
        method:"post",
        data:data.value,



      })
      .then(res=>{
        if(res.data.data>0)
        {
          alert('提交成功')
          router.push('/demo2');
        }
      })
      .catch(err=>{



      })

    })


</script>

<style scoped>

</style>